package com.hjj.concurrence.syncMethod.t4;

public class HasSelfPrivateNum {
    private int num = 0;

    public synchronized void addI(String username) {
        try {
            if (username.equals("a")) {
                num = 100;
                System.out.println("a set over");
                Thread.sleep(2000);
            } else {
                num = 200;
                System.out.println("b set over");
            }
            System.out.println(username + " num=" + num);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    /**
     * 多个线程多个锁
     * @param args
     */
    public static void main(String[] args) {
        HasSelfPrivateNum num1 = new HasSelfPrivateNum();
        HasSelfPrivateNum num2 = new HasSelfPrivateNum();
        new ThreadA(num1).start();
        new ThreadB(num2).start();
    }
}
